package menu;

/**
 * build menu with array
 * @author yuanml
 */
public class ArrayMenu implements Menu{
    public static final int MAX_ITEMS = 6;
    int numOfItems = 0;
    MenuItem[] items;

    public ArrayMenu() {
        items = new MenuItem[MAX_ITEMS];
        addItems("arrayItem1","array item 1",true,19.45);
        addItems("arrayItem2","array item 2",false,78.42);
        addItems("arrayItem3","array item 3",true,56.12);
        addItems("arrayItem4","array item 4",false,73.18);
    }

    public void addItems(String name, String description, boolean vegetarian, double price) {
        if (numOfItems > MAX_ITEMS) {
            System.err.println("Menu is full, can't add item.");
            return;
        }
        MenuItem menuItem = new MenuItem();
        menuItem.setName(name);
        menuItem.setDescription(description);
        menuItem.setVegetarian(vegetarian);
        menuItem.setPrice(price);
        items[numOfItems++] = menuItem;
    }

    public MenuItem[] getMenuItems() {
        return items;
    }

    @Override
    public Iterator createIterator() {
        return new ArrayMenuIterator(items);
    }
}
